﻿using System;
using System.Configuration;
using mojoPortal.Net;
using mojoPortal.Web;
using Resources;
using mojoPortal.Web.Framework;
using System.Collections;
using mojoPortal.Business;
using ud_gSDMS.Code_Service;
using mojoPortal.Business.WebHelpers;
using System.IO;
using Brettle.Web.NeatUpload;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Web.UI;
namespace ud_gSDMS.Member
{
    public partial class Salary : mojoBasePage
    {
        private int pageId = -1;
        private int moduleId = -1;
        private string id;
        private Literal lstNgachTam;
        private Literal lstBacTam;
        private Literal lstHSTam;
        private int editindextam;
        private SiteUser _siteUser;
        protected String cacheDependencyKey;
        DBQLNS _respository=new DBQLNS();
        
        void Page_Load(object sender, EventArgs e)
        {
            _siteUser = SiteUtils.GetCurrentSiteUser();
            if (_siteUser == null)
            {
                WebUtils.SetupRedirect(this, SiteRoot + "/AccessDenied.aspx");
            }

            if (!Page.IsPostBack)
            {
                PopulateLabels();
                PopulateControls();
            }
        }
        private void PopulateLabels()
        {
            leftMenuItem.CurrentSite = Request.RawUrl;
            
            List<ud_QTLuong> lst = new List<ud_QTLuong>();
            lst = _respository.getALLQTLuongOfPerson(1);
            
            Session["Sa"] = lst;
        }
        private void BindData()
        {
            gvChildInfo.DataSource = Session["Sa"];
            gvChildInfo.DataBind();
        }

        private void PopulateControls()
        {
            BindData();
        }
        #region OnInit

        protected override void OnPreInit(EventArgs e)
        {
            AllowSkinOverride = true;
            base.OnPreInit(e);
            Load += Page_Load;
        }

        protected override void OnInit(EventArgs e)
        {
            LoadParams();
            LoadPanels();
            base.OnInit(e);
            SuppressPageMenu();
        }

        private void LoadParams()
        {
            pageId = WebUtils.ParseInt32FromQueryString("pageid", pageId);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", true, moduleId);
            id = WebUtils.ParseStringFromQueryString("id", id);
            cacheDependencyKey = "Module-" + moduleId.ToInvariantString();
        }

        private void LoadPanels()
        {
            bool showLeftColumnAdmin = ConfigHelper.GetBoolProperty("ShowLeftColumnAdmin", false);
            bool showRightColumnAdmin = ConfigHelper.GetBoolProperty("ShowRightColumnAdmin", false);
            bool showTopColumnAdmin = ConfigHelper.GetBoolProperty("ShowTopColumnAdmin", false);
            bool showBottomColumnAdmin = ConfigHelper.GetBoolProperty("ShowBottomColumnAdmin", false);
            int showCenterColumnAdmin = ConfigHelper.GetIntProperty("ShowCenterColumnAdmin", 0);
            LoadSideContent(showLeftColumnAdmin, showRightColumnAdmin, showTopColumnAdmin, showBottomColumnAdmin, showCenterColumnAdmin);
        }
        protected void ngach_Load(object sender, EventArgs e)
        {
           
            DropDownList dr = (DropDownList)sender;

            dr.DataValueField = "ID";
            dr.DataTextField = "Ngach";
            List<ud_DM_MaNgach> lstNgach = _respository.getAllNgach();
            dr.DataSource = lstNgach;
            
            dr.DataBind();
            
            for (int i = 0; i < dr.Items.Count; i++)
            {
                if (dr.Items[i].Text == lstNgachTam.Text)
                {
                    dr.SelectedValue = dr.Items[i].Text;
                    break;
                }
            }
        }

        protected void bac_Load(object sender, EventArgs e)
        {

            DropDownList dr = (DropDownList)sender;

            dr.DataValueField = "ID";
            dr.DataTextField = "Name";
            DropDownList tam = (DropDownList) gvChildInfo.Rows[editindextam].FindControl("drdl_ngach");
            List<ud_DM_Bac> lstbac = _respository.getAllBac(tam.SelectedItem.Text);
            dr.DataSource = lstbac;
            dr.DataBind();
            
            for (int i = 0; i < dr.Items.Count; i++)
            {
                if (dr.Items[i].Text == lstBacTam.Text)
                {
                    dr.SelectedValue = dr.Items[i].Text;
                    break;
                }
            }
        }

        protected void heso_Load(object sender, EventArgs e)
        {

            DropDownList dr = (DropDownList)sender;

            dr.DataValueField = "ID";
            dr.DataTextField = "Name";
            List<ud_DM_HeSo> lstheso = _respository.getAllHeso(lstNgachTam.Text, lstBacTam.Text);
            dr.DataSource = lstheso;
            dr.DataBind();
            
            for (int i = 0; i < dr.Items.Count; i++)
            {
                if (dr.Items[i].Text == lstHSTam.Text)
                {
                    dr.SelectedValue = dr.Items[i].Text;
                    break;
                }
            }
        }

        #endregion

        protected void gvChildInfo_RowEditing(object sender, GridViewEditEventArgs e)
        {
            lstNgachTam = (Literal)gvChildInfo.Rows[e.NewEditIndex].FindControl("ltrMaNgach");
            lstBacTam = (Literal)gvChildInfo.Rows[e.NewEditIndex].FindControl("ltrBac");
            lstHSTam = (Literal)gvChildInfo.Rows[e.NewEditIndex].FindControl("ltrHeSo");
            gvChildInfo.EditIndex = e.NewEditIndex;
            editindextam = e.NewEditIndex;
            BindData();
        }

        protected void gvChildInfo_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvChildInfo.EditIndex = -1;
            BindData();
        }

        protected void gvChildInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            List<SalaryP> l = (List<SalaryP>)Session["Sa"];
            TextBox txt_thangnam = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt1");
            TextBox txt_mangach = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt2");
            TextBox txt_bac = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt3");
            TextBox txt_heso = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt4");
            TextBox txt_pc85 = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt5");
            TextBox txt_hspctn = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt6");
            TextBox txt_hspcth = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt7");
            TextBox txt_hspcdh = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt8");
            TextBox txt_hspckv = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt9");
            TextBox txt_hspckv2 = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt10");
            TextBox txt_hspcdt = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt11");
            TextBox txt_hspcvk = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt12");
            TextBox txt_hspct = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt13");
            TextBox txt_lydo = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt14");

            SalaryP newsalary = new SalaryP(txt_thangnam.Text, txt_mangach.Text, txt_bac.Text, txt_heso.Text, txt_pc85.Text,
                txt_hspctn.Text,txt_hspcth.Text,txt_hspcdh.Text,txt_hspckv.Text,txt_hspckv2.Text,txt_hspcdt.Text,txt_hspcvk.Text,txt_hspct.Text,txt_lydo.Text);
            l[e.RowIndex] = newsalary;
            gvChildInfo.EditIndex = -1;
            BindData();
        }

        protected void gvChildInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            List<SalaryP> l = (List<SalaryP>)Session["Sa"];
            l.RemoveAt(e.RowIndex);
            BindData();
        }
    }

    public class SalaryP
    {
        public string ThangNam { get; set; }
        public string MaNgach { get; set; }
        public string Bac { get; set; }
        public string HeSo { get; set; }
        public string Pc85 { get; set; }
        public string HSPCTN { get; set; }
        public string HSPCTH { get; set; }
        public string HSPCDH { get; set; }
        public string HSPCKV { get; set; }
        public string HSPCKV2 { get; set; }
        public string HSPCDT { get; set; }
        public string HSPCVK { get; set; }
        public string HSPCT { get; set; }
        public string LyDo { get; set; }
        public SalaryP(string thangnam, string mangach, string bac, string heso, string pc85, string hspctn, string hspcth, string hspcdh, string hspckv, string hspckv2,
            string hspcdt, string hspcvk, string hspct, string lydo)
        {
            this.ThangNam = thangnam;
            this.MaNgach = mangach;
            this.Bac = bac;
            this.HeSo = heso;
            this.Pc85 = pc85;
            this.HSPCTN = hspctn;
            this.HSPCTH = hspcth;
            this.HSPCDH = hspcdh;
            this.HSPCKV = hspckv;
            this.HSPCKV2 = hspckv2;
            this.HSPCDT = hspcdt;
            this.HSPCVK = hspcvk;
            this.HSPCT = hspct;
            this.LyDo = lydo;
        }
    }

    
}